package com.example.shuiwen;

import androidx.appcompat.app.AppCompatActivity;


import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.webkit.WebView;
import android.widget.Toast;

import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.runtime.Permission;

public class MainActivity extends AppCompatActivity implements WebCall {
   private String deviceId="none";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (getSupportActionBar() != null) {
            getSupportActionBar().hide();
        }
//        TelephonyManager TelephonyMgr = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
        deviceId  = Settings.System.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
        ;
        Log.e("测试",deviceId);
        AndPermission.with(this)
                .runtime()
                .permission(Permission.WRITE_EXTERNAL_STORAGE)
                .onGranted(permissions -> {
                    initMap();
                })
                .onDenied(permissions -> {
                    Toast.makeText(getApplicationContext(), "获取权限失败无法打开地图",
                            Toast.LENGTH_LONG).show();
                })
                .start();


    }


    private void initMap() {
        WebView webView = (WebView) findViewById(R.id.webView);
        WebMapView webMapView = new WebMapView(webView);
        webMapView.loadMapHtml("index.html#/?id="+deviceId);
        webMapView.setWebCall(this);
    }

    @Override
    public void loadWeb() {
        try {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://61.161.205.158/"));
            startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
